home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Topics.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  35.6 KB  |  1,112 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Topic display module
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 18th February 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new Topics;
  26.  
  27. class Topics {
  28.  
  29.     var $output    = "";
  30.     var $base_url  = "";
  31.     var $html      = "";
  32.     var $moderator = array();
  33.     var $forum     = array();
  34.     var $topic     = array();
  35.     var $category  = array();
  36.     var $mem_titles = array();
  37.     var $mod_action = array();
  38.     var $poll_html  = "";
  39.     var $colspan    = 0;
  40.     var $parser     = "";
  41.     var $mimetypes  = "";
  42.     var $nav_extra  = "";
  43.     var $read_array = array();
  44.     
  45.     /***********************************************************************************/
  46.     //
  47.     // Our constructor, load words, load skin, print the topic listing
  48.     //
  49.     /***********************************************************************************/
  50.     
  51.     function Topics() {
  52.     
  53.     
  54.         global $ibforums, $DB, $std, $print, $skin_universal;
  55.         
  56.         require "./Skin/".$ibforums->skin_id."/skin_topic.php";
  57.  
  58.         //-------------------------------------
  59.         // Compile the language file
  60.         //-------------------------------------
  61.         
  62.         $ibforums->lang = $std->load_words($ibforums->lang, 'lang_topic', $ibforums->lang_id);
  63.  
  64.         $this->html     = new skin_topic();
  65.         
  66.         require "./sources/lib/post_parser.php";
  67.         
  68.         $this->parser = new post_parser();
  69.         
  70.         //-------------------------------------
  71.         // Check the input
  72.         //-------------------------------------
  73.         
  74.         $ibforums->input['t'] = $std->is_number($ibforums->input['t']);
  75.         $ibforums->input['f'] = $std->is_number($ibforums->input['f']);
  76.         
  77.         if ( ($ibforums->input['t'] < 0 or $ibforums->input['f'] < 0)  )
  78.         {
  79.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  80.         }
  81.         
  82.         //-------------------------------------
  83.         // Get the forum info based on the forum ID, get the category name, ID, and get the topic details
  84.         //-------------------------------------
  85.         
  86.         $DB->query("SELECT t.*, f.name as forum_name, f.id as forum_id, f.read_perms, f.reply_perms, f.parent_id, f.start_perms, f.allow_poll, f.password, f.posts as forum_posts, f.topics as forum_topics, f.use_attach, c.name as cat_name, c.id as cat_id FROM ibf_topics t, ibf_forums f , ibf_categories c where t.tid='".$ibforums->input[t]."' and f.id = t.forum_id and f.category=c.id");
  87.         
  88.         $this->topic = $DB->fetch_row();
  89.         
  90.         $this->forum = array( 'id'           => $this->topic['forum_id']          ,
  91.                               'name'         => $this->topic['forum_name']        ,
  92.                               'posts'        => $this->topic['forum_posts']       ,
  93.                               'topics'       => $this->topic['forum_topics']      ,
  94.                               'read_perms'   => $this->topic['read_perms']        ,
  95.                               'allow_poll'   => $this->topic['allow_poll']        ,
  96.                               'use_attach'   => $this->topic['use_attach']        ,
  97.                               'parent_id'    => $this->topic['parent_id']         ,
  98.                               'password'     => $this->topic['password']
  99.                             );
  100.                             
  101.         $this->category = array( 'name'   => $this->topic['cat_name'],
  102.                                  'id'     => $this->topic['cat_id']  ,
  103.                                );
  104.                                
  105.         
  106.         //-------------------------------------
  107.         // Error out if we can not find the forum
  108.         //-------------------------------------
  109.         
  110.         if (!$this->forum['id'])
  111.         {
  112.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  113.         }
  114.         
  115.         //-------------------------------------
  116.         // Error out if we can not find the topic
  117.         //-------------------------------------
  118.         
  119.         if (!$this->topic['tid'])
  120.         {
  121.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  122.         }
  123.         
  124.         //-------------------------------------
  125.         // If this forum is a link, then 
  126.         // redirect them to the new location
  127.         //-------------------------------------
  128.         
  129.         if ($this->topic['state'] == 'link')
  130.         {
  131.             $f_stuff = explode("&", $this->topic['moved_to']);
  132.             $print->redirect_screen( $ibforums->lang['topic_moved'], "act=ST&f={$f_stuff[1]}&t={$f_stuff[0]}" );
  133.         }
  134.         
  135.         //-------------------------------------
  136.         // Unserialize the read array and parse into
  137.         // array
  138.         //-------------------------------------
  139.         
  140.         if ( $read = $std->my_getcookie('topicsread') )
  141.         {
  142.             $this->read_array = unserialize(stripslashes($read));
  143.             
  144.             if (! is_array($this->read_array) )
  145.             {
  146.                 $this->read_array = array();
  147.             }
  148.         }
  149.         
  150.         //--------------------------------------------------------------------
  151.         // Are we looking for an older / newer topic?
  152.         //--------------------------------------------------------------------
  153.         
  154.         if ( isset($ibforums->input['view']) )
  155.         {
  156.             if ($ibforums->input['view'] == 'new')
  157.             {
  158.                 $DB->query("SELECT * from ibf_topics WHERE forum_id='".$this->forum['id']."' AND approved=1 AND state <> 'link' AND last_post > ".$this->topic['last_post']." "
  159.                           ."ORDER BY last_post ASC LIMIT 0,1");
  160.                           
  161.                 if ( $DB->get_num_rows() )
  162.                 {
  163.                     $this->topic = $DB->fetch_row();
  164.                     $ibforums->input['t'] = $this->topic['tid'];
  165.                 }
  166.                 else
  167.                 {
  168.                     $std->Error( array( LEVEL => 1, MSG => 'no_newer') );
  169.                 }
  170.             }
  171.             else if ($ibforums->input['view'] == 'old')
  172.             {
  173.                 $DB->query("SELECT * from ibf_topics WHERE forum_id='".$this->forum['id']."' AND approved=1 AND state <> 'link' AND last_post < ".$this->topic['last_post']." "
  174.                           ."ORDER BY last_post DESC LIMIT 0,1");
  175.                           
  176.                 if ( $DB->get_num_rows() )
  177.                 {
  178.                     $this->topic = $DB->fetch_row();
  179.                     $ibforums->input['t'] = $this->topic['tid'];
  180.                 }
  181.                 else
  182.                 {
  183.                     $std->Error( array( LEVEL => 1, MSG => 'no_older') );
  184.                 }
  185.             }
  186.             else if ($ibforums->input['view'] == 'getlastpost')
  187.             {
  188.                 
  189.                 $this->return_last_post();
  190.                 
  191.             }
  192.             else if ($ibforums->input['view'] == 'getnewpost')
  193.             {
  194.                 
  195.                 $st  = 0;
  196.                 $pid = "";
  197.                 
  198.                 $last_time = isset($this->read_array[ $this->topic['tid'] ]) ? $this->read_array[ $this->topic['tid'] ] : $ibforums->input['last_visit'];
  199.             
  200.                 $DB->query("SELECT pid, post_date FROM ibf_posts WHERE queued <> 1 AND topic_id='".$this->topic['tid']."' AND post_date > '".$last_time."' ORDER BY post_date LIMIT 1");
  201.                 
  202.                 if ( $post = $DB->fetch_row() )
  203.                 {
  204.                 
  205.                     $pid = "&#entry".$post['pid'];
  206.                 
  207.                     $DB->query("SELECT COUNT(pid) as posts FROM ibf_posts WHERE topic_id='".$this->topic['tid']."' AND pid <= '".$post['pid']."'");
  208.                     
  209.                     $cposts = $DB->fetch_row();
  210.                     
  211.                     if ( (($cposts['posts']) % $ibforums->vars['display_max_posts']) == 0 )
  212.                     {
  213.                         $pages = ($cposts['posts']) / $ibforums->vars['display_max_posts'];
  214.                     }
  215.                     else
  216.                     {
  217.                         $number = ( ($cposts['posts']) / $ibforums->vars['display_max_posts'] );
  218.                         $pages = ceil( $number);
  219.                     }
  220.                     
  221.                     $st = ($pages - 1) * $ibforums->vars['display_max_posts'];
  222.                     
  223.                     $std->boink_it($ibforums->base_url."&act=ST&f=".$this->topic['forum_id']."&t=".$this->topic['tid']."&st=$st".$pid);
  224.                     exit();
  225.                 }
  226.                 else
  227.                 {
  228.                     $this->return_last_post();
  229.                 }
  230.             }
  231.         }
  232.         
  233.         $this->base_url = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}?s={$ibforums->session_id}";
  234.         
  235.         $this->forum['JUMP'] = $std->build_forum_jump();
  236.         $this->forum['JUMP'] = preg_replace( "!#Forum Jump#!", $ibforums->lang['forum_jump'], $this->forum['JUMP']);
  237.         
  238.         //-------------------------------------
  239.         // Check viewing permissions, private forums,
  240.         // password forums, etc
  241.         //-------------------------------------
  242.         
  243.         if ( (!$this->topic['pinned']) and (!$ibforums->member['g_other_topics']) )
  244.         {
  245.             $std->Error( array( LEVEL => 1, MSG => 'no_view_topic') );
  246.         }
  247.         
  248.         $bad_entry = $this->check_access();
  249.         
  250.         if ($bad_entry == 1)
  251.         {
  252.             $std->Error( array( LEVEL => 1, MSG => 'no_view_topic') );
  253.         }      
  254.         
  255.         //-------------------------------------
  256.         // Update the topic views counter
  257.         //-------------------------------------
  258.         
  259.         $DB->query("UPDATE ibf_topics SET views=views+1 WHERE tid='".$this->topic['tid']."'");
  260.         
  261.         //-------------------------------------
  262.         // Update the topic read cookie
  263.         //-------------------------------------
  264.         
  265.         if ($ibforums->member['id'])
  266.         {
  267.             $this->read_array[$this->topic['tid']] = time();
  268.             
  269.             $std->my_setcookie('topicsread', serialize($this->read_array), -1 );
  270.         }
  271.         
  272.         //----------------------------------------
  273.         // If this is a sub forum, we need to get
  274.         // the cat details, and parent details
  275.         //----------------------------------------
  276.         
  277.         if ($this->forum['parent_id'] > 0)
  278.         {
  279.         
  280.             $DB->query("SELECT f.id as forum_id, f.name as forum_name, c.id, c.name FROM ibf_forums f, ibf_categories c WHERE f.id='".$this->forum['parent_id']."' AND c.id=f.category");
  281.             
  282.             $row = $DB->fetch_row();
  283.             
  284.             $this->category['id']   = $row['id'];
  285.             $this->category['name'] = $row['name'];
  286.         
  287.             $this->nav_extra = "<a href='".$this->base_url."&act=SF&f={$row['forum_id']}'>{$row['forum_name']}</a>";
  288.         }
  289.         
  290.         
  291.          //-------------------------------------
  292.          // Get all the member groups and
  293.          // member title info
  294.          //-------------------------------------
  295.         
  296.         $DB->query("SELECT id, title, pips, posts from ibf_titles ORDER BY posts DESC");
  297.         while ($i = $DB->fetch_row())
  298.         {
  299.              $this->mem_titles[ $i['id'] ] = array(
  300.                                                  'TITLE' => $i['title'],
  301.                                                  'PIPS'  => $i['pips'],
  302.                                                  'POSTS' => $i['posts'],
  303.                                                );
  304.         }
  305.         
  306.         //-------------------------------------
  307.         // Are we a moderator?
  308.         //-------------------------------------
  309.         
  310.         if ( ($ibforums->member['id']) and ($ibforums->member['g_is_supmod'] != 1) )
  311.         {
  312.             $DB->query("SELECT * FROM ibf_moderators WHERE forum_id='".$this->forum['id']."' and member_id='".$ibforums->member['id']."'");
  313.             $this->moderator = $DB->fetch_row();
  314.         }
  315.         
  316.         $this->mod_action = array( 'CLOSE_TOPIC'  => '00',
  317.                                    'OPEN_TOPIC'   => '01',
  318.                                    'MOVE_TOPIC'   => '02',
  319.                                    'DELETE_TOPIC' => '03',
  320.                                    'EDIT_TOPIC'   => '05',
  321.                                    'PIN_TOPIC'    => '15',
  322.                                    'UNPIN_TOPIC'  => '16'
  323.                                  );
  324.         
  325.         
  326.         //-------------------------------------
  327.         // Get the reply, and posting buttons
  328.         //------------------------------------- 
  329.         
  330.         $this->topic['POLL_BUTTON'] = $this->forum['allow_poll']
  331.                                          ? "<a href='".$this->base_url."&act=Post&CODE=10&f=".$this->forum['id']."'>{$ibforums->skin['A_POLL']}</a>"
  332.                                          : '';
  333.                                          
  334.         $this->topic['REPLY_BUTTON']  = $this->reply_button();
  335.         
  336.         
  337.         //-------------------------------------
  338.         // Generate the forum page span links
  339.         //-------------------------------------
  340.         
  341.         if ($ibforums->input['hl'])
  342.         {
  343.             $hl = '&hl='.$ibforums->input['hl'];
  344.         }
  345.         
  346.         $this->topic['SHOW_PAGES']
  347.             = $std->build_pagelinks( array( 'TOTAL_POSS'  => ($this->topic['posts']+1),
  348.                                             'PER_PAGE'    => $ibforums->vars[display_max_posts],
  349.                                             'CUR_ST_VAL'  => $ibforums->input['st'],
  350.                                             'L_SINGLE'    => "",
  351.                                             'L_MULTI'     => $ibforums->lang['multi_page_topic'],
  352.                                             'BASE_URL'    => $this->base_url."&act=ST&f=".$this->forum['id']."&t=".$this->topic['tid'].$hl,
  353.                                           )
  354.                                    );
  355.                                    
  356.         if ( ($this->topic['posts'] + 1) > $ibforums->vars['display_max_posts'])
  357.         {
  358.             $this->topic['go_new'] = $this->html->golastpost_link($this->forum['id'], $this->topic['tid'] );
  359.         }
  360.                                    
  361.         //-------------------------------------
  362.         // Do we have a poll?
  363.         //-------------------------------------
  364.         
  365.         if ($this->topic['poll_state'])
  366.         {
  367.             $this->output .= $this->parse_poll();
  368.         }
  369.                                    
  370.                                    
  371.         //-------------------------------------
  372.         // Fix up some of the words
  373.         //-------------------------------------
  374.         
  375.         $this->topic['TOPIC_START_DATE'] = $std->get_date( $this->topic['start_date'], 'LONG' );
  376.         
  377.         $ibforums->lang['topic_stats'] = preg_replace( "/<#START#>/", $this->topic['TOPIC_START_DATE'], $ibforums->lang['topic_stats']);
  378.         $ibforums->lang['topic_stats'] = preg_replace( "/<#POSTS#>/", $this->topic['posts']           , $ibforums->lang['topic_stats']);
  379.         
  380.         if ($this->topic['description']) {
  381.             $this->topic['description'] = ', '.$this->topic['description'];
  382.         }
  383.         
  384.  
  385.         //-------------------------------------
  386.         // Render the page top
  387.         //-------------------------------------
  388.         
  389.         $this->output .= $this->html->PageTop( array( 'TOPIC' => $this->topic, 'FORUM' => $this->forum ) );
  390.         
  391.         /*******************************************************************************************/
  392.         // Grab the posts we'll need
  393.         /*******************************************************************************************/
  394.         
  395.         $first = $ibforums->input['st'];
  396.         if (!$first) $first = 0;
  397.         
  398.         $DB->query( "SELECT p.*, ".
  399.                     "m.id,m.name,m.mgroup,m.email,m.joined,m.avatar,m.avatar_size,m.posts,m.aim_name,m.icq_number,m.signature, m.website,m.yahoo,m.title,m.hide_email,m.msnname, ".
  400.                     "g.g_id, g.g_title, g.g_icon ".
  401.                     "FROM ibf_posts p, ibf_members m, ibf_groups g ".
  402.                     "WHERE p.topic_id='".$this->topic['tid']."' and p.queued !='1' AND p.author_id=m.id AND g.g_id=m.mgroup ".
  403.                     "ORDER BY p.pid LIMIT $first, ".$ibforums->vars['display_max_posts']);
  404.                     
  405.         if ( ! $DB->get_num_rows() )
  406.         {
  407.             if ($first >= $ibforums->vars['display_max_posts'])
  408.             {
  409.                 // Get the correct number of replies...
  410.                 
  411.                 $newq = $DB->query("SELECT COUNT(pid) as pcount FROM ibf_posts p, ibf_members m WHERE p.topic_id='".$this->topic['tid']."' and p.queued !='1' AND p.author_id=m.id");
  412.                 $pcount = $DB->fetch_row($newq);
  413.                 
  414.                 $pcount['pcount'] = $pcount['pcount'] > 0 ? $pcount['pcount'] - 1 : 0;
  415.                 
  416.                 // Update the post table...
  417.                 
  418.                 if ($pcount['pcount'] > 1)
  419.                 {
  420.                     $DB->query("UPDATE ibf_topics SET posts='".$pcount['pcount']."' WHERE tid='".$this->topic['tid']."'");
  421.                 }
  422.                 
  423.                 $std->boink_it($ibforums->base_url."&act=ST&f={$this->forum['id']}&t={$this->topic['tid']}&view=getlastpost");
  424.                 exit();
  425.             }
  426.         }
  427.                 
  428.                     
  429.         $cached_members = array();
  430.         
  431.         //-------------------------------------
  432.         // Format and print out the topic list
  433.         //-------------------------------------
  434.         
  435.         $post_count = 0;  // Use this as our master bater, er... I mean counter.
  436.         
  437.         while ( $row = $DB->fetch_row() ) {
  438.         
  439.             $poster = array();
  440.         
  441.             // Get the member info. We parse the data and cache it.
  442.             // It's likely that the same member posts several times in
  443.             // one page, so it's not efficient to keep parsing the same
  444.             // data
  445.             
  446.             if ($row['author_id'] != 0)
  447.             {
  448.                 // Is it in the hash?
  449.                 if ( isset($cached_members[ $row['author_id'] ]) )
  450.                 {
  451.                     // Ok, it's already cached, read from it
  452.                     $poster = $cached_members[ $row['author_id'] ];
  453.                     $row['name_css'] = 'normalname';
  454.                 }
  455.                 else
  456.                 {
  457.                     $row['name_css'] = 'normalname';
  458.                     $poster = $this->parse_member( &$row );
  459.                     // Add it to the cached list
  460.                     $cached_members[ $row['author_id'] ] = $poster;
  461.                 }
  462.             }
  463.             else
  464.             {
  465.                 // It's definately a guest...
  466.                 $poster = $std->set_up_guest( $row['author_name'] );
  467.                 $row['name_css'] = 'unreg';
  468.             }
  469.             
  470.             //--------------------------------------------------------------
  471.             
  472.             $row['post_css'] = $post_count % 2 ? 'post1' : 'post2';
  473.             
  474.             
  475.             //--------------------------------------------------------------
  476.             
  477.             $row['post'] = preg_replace( "/<!--EDIT\|(.+?)\|(.+?)-->/", "<span id='edit'>".$ibforums->lang['edited_by']." \\1 - \\2</span>", $row['post'] );
  478.             
  479.             //--------------------------------------------------------------
  480.             
  481.             if (!$ibforums->member['view_img'])
  482.             {
  483.                 $row['post'] = preg_replace( "/<img src=[\"'](.+?)[\"'].+?".">/", "(IMG:<a href='\\1' target='_blank'>\\1</a>)", $row['post'] );
  484.             }
  485.             
  486.             //--------------------------------------------------------------
  487.             
  488.             if ($ibforums->input['hl'])
  489.             {
  490.             
  491.                 $keywords = str_replace( "+", " ", $ibforums->input['hl'] );
  492.                 
  493.                 if ( preg_match("/,(and|or),/i", $keywords) )
  494.                 {
  495.                     while ( preg_match("/,(and|or),/i", $keywords, $match) )
  496.                     {
  497.                         $word_array = explode( ",".$match[1].",", $keywords );
  498.                         
  499.                         if (is_array($word_array))
  500.                         {
  501.                             foreach ($word_array as $keywords)
  502.                             {
  503.                                 $row['post'] = preg_replace( "/(^|\s)($keywords)(\s|$)/i", "\\1<span id='highlight'>\\2</span>\\3", $row['post'] );
  504.                             }
  505.                         }
  506.                     }
  507.                 }
  508.                 else
  509.                 {
  510.                     $row['post'] = preg_replace( "/(^|\s)($keywords)(\s|$)/i", "\\1<span id='highlight'>\\2</span>\\3", $row['post'] );
  511.                 }
  512.             }
  513.                 
  514.             //--------------------------------------------------------------
  515.             
  516.             if ( ($post_count != 0 and $first == 0) or ($first > 0) )
  517.             {
  518.                 $row['delete_button'] = $this->delete_button($row['pid'], $poster);
  519.             }
  520.             
  521.             
  522.             $row['edit_button']   = $this->edit_button($row['pid'], $poster);
  523.             $row['post_date']     = $std->get_date( $row['post_date'], 'LONG' );
  524.             $row['post_icon']     = $row['icon_id']
  525.                               ? "<img src='".$ibforums->vars['img_url']."/icon{$row['icon_id']}.gif' alt=''>  "
  526.                               : "";
  527.             
  528.             $row['ip_address']  = $this->view_ip($row, $poster);
  529.             
  530.             $row['report_link'] = $ibforums->vars[REPORT_POST_ENABLED] && $ibforums->member['id']
  531.                                 ? $this->html->report_link($row)
  532.                                 : "";
  533.             
  534.             //--------------------------------------------------------------
  535.                               
  536.             if ($row['attach_id'])
  537.             {
  538.                 // If we've not already done so, lets grab our mime-types
  539.                 
  540.                 if ( !is_array($this->mimetypes) )
  541.                 {
  542.                     require "./conf_mime_types.php";
  543.                     $this->mimetypes = $mime_types;
  544.                     unset($mime_types);
  545.                 }
  546.             
  547.                 // Is it an image, and are we viewing the image in the post?
  548.                 if ( 
  549.                      ($ibforums->vars['show_img_upload'])
  550.                        and
  551.                      (
  552.                             $row['attach_type'] == 'image/gif'
  553.                          or $row['attach_type'] == 'image/jpeg'
  554.                          or $row['attach_type'] == 'image/pjpeg'
  555.                          or $row['attach_type'] == 'image/x-png'
  556.                      )
  557.                     ) {
  558.                     $row['attachment'] = $this->html->Show_attachments_img( array( 'file_name' => $row['attach_id']) );
  559.                 } else {
  560.                     $row['attachment'] = $this->html->Show_attachments( array (
  561.                                                                                       'hits'  => $row['attach_hits'],
  562.                                                                                       'image' => $this->mimetypes[ $row['attach_type'] ][1],
  563.                                                                                       'name'  => $row['attach_file'],
  564.                                                                                       'pid'   => $row['pid'],
  565.                                                                                     )
  566.                                                                             );
  567.                 }
  568.             }
  569.             
  570.             //--------------------------------------------------------------
  571.             // Siggie stuff
  572.             //--------------------------------------------------------------
  573.             
  574.             if (!$ibforums->vars[SIG_SEP]) $ibforums->vars[SIG_SEP] = "<br><br>--------------------<br>";
  575.             
  576.             if ($poster['signature'] and $ibforums->member['view_sigs'])
  577.             {
  578.                 if ($row['use_sig'] == 1)
  579.                 {
  580.                     $row['signature'] = "<!--Signature-->{$ibforums->vars[SIG_SEP]}<span id='signature'>{$poster['signature']}</span><!--E-Signature-->";
  581.                 }
  582.                 else
  583.                 {
  584.                     $row['signature'] = "";
  585.                 }
  586.                                 
  587.             }
  588.             else
  589.             {
  590.                 $row['signature'] = "";
  591.             }
  592.             
  593.             // Fix up the membername so it links to the members profile
  594.             
  595.             if ($poster['id'])
  596.             {
  597.                 $poster['name'] = "<a href='{$this->base_url}&act=Profile&CODE=03&MID={$poster['id']}'>{$poster['name']}</a>";
  598.             }
  599.             
  600.             $this->output .= $this->html->RenderRow( array( 'POST' => $row, 'POSTER' => $poster ) );
  601.             
  602.             $post_count++;
  603.                 
  604.         }
  605.         
  606.         //-------------------------------------
  607.         // Print the footer
  608.         //-------------------------------------
  609.         
  610.         $this->output .= $this->html->TableFooter( array( 'TOPIC' => $this->topic, 'FORUM' => $this->forum ) );
  611.         
  612.         //-------------------------------------
  613.         // Print all the output
  614.         //-------------------------------------
  615.         
  616.         $this->output .= $this->moderation_panel();
  617.         
  618.         // Pass it to our print routine
  619.         
  620.         $print->add_output("$this->output");
  621.         $print->do_output( array( 'TITLE'    => $ibforums->vars['board_name']." -> {$this->topic['title']}",
  622.                                    'JS'       => 1,
  623.                                    'NAV'      => array( 
  624.                                                           "<a href='".$this->base_url."&act=SC&c={$this->category['id']}'>{$this->category['name']}</a>",
  625.                                                           $this->nav_extra,
  626.                                                           "<a href='".$this->base_url."&act=SF&f={$this->forum['id']}'>{$this->forum['name']}</a>",
  627.                                                         ),
  628.                               ) );
  629.                         
  630.     }
  631.     
  632.     /*********************************************************************/
  633.     // Parse the member info
  634.     /*********************************************************************/
  635.     
  636.     function parse_member($member=array()) {
  637.         global $ibforums, $std, $DB;
  638.     
  639.         $member['avatar'] = $std->get_avatar( $member['avatar'], $ibforums->member['view_avs'], $member['avatar_size'] );
  640.         
  641.         $pips = 0;
  642.         
  643.         foreach($this->mem_titles as $k => $v)
  644.         {
  645.             if ($member['posts'] >= $v['POSTS'])
  646.             {
  647.                 if (!$member['title'])
  648.                 {
  649.                     $member['title'] = $this->mem_titles[ $k ]['TITLE'];
  650.                 }
  651.                 $pips = $v['PIPS'];
  652.                 break;
  653.             }
  654.         }
  655.         
  656.         
  657.         if ($member['g_icon'])
  658.         {
  659.             $member['member_rank_img'] = "<img src='{$ibforums->vars[TEAM_ICON_URL]}/{$member['g_icon']}' border='0'>";
  660.         }
  661.         else
  662.         {
  663.             if ($pips)
  664.             {
  665.                 if ( preg_match( "/^\d+$/", $pips ) )
  666.                 {
  667.                     for ($i = 1; $i <= $pips; ++$i)
  668.                     {
  669.                         $member['member_rank_img'] .= $ibforums->skin['A_STAR'];
  670.                     }
  671.                 }
  672.                 else
  673.                 {
  674.                     $member['member_rank_img'] = "<img src='{$ibforums->vars['TEAM_ICON_URL']}/$pips' border='0'>";
  675.                 }
  676.             }
  677.         }
  678.                                
  679.         $member['member_joined'] = $ibforums->lang['m_joined'].' '.$std->get_date( $member['joined'], 'JOINED' );
  680.         
  681.         $member['member_group'] = $ibforums->lang['m_group'].' '.$member['g_title'];
  682.         
  683.         $member['member_posts'] = $ibforums->lang['m_posts'].' '.$member['posts'];
  684.         
  685.         $member['member_number'] = $ibforums->lang['member_no'].' '.$member['id'];
  686.         
  687.         $member['profile_icon'] = "<a href='{$this->base_url}&act=Profile&CODE=03&MID={$member['id']}'>{$ibforums->skin['P_PROFILE']}</a> ";
  688.         
  689.         $member['message_icon'] = "<a href='{$this->base_url}&act=Msg&CODE=04&MID={$member['id']}'>{$ibforums->skin['P_MSG']}</a> ";
  690.         
  691.         if (!$member['hide_email'])
  692.         {
  693.             $member['email_icon'] = "<a href='{$this->base_url}&act=Mail&CODE=00&MID={$member['id']}'>{$ibforums->skin['P_EMAIL']}</a> ";
  694.         }
  695.         
  696.         if ( $member['website'] and preg_match( "/^http:\/\/\S+$/", $member['website'] ) )
  697.         {
  698.             $member['website_icon'] = "<a href='{$member['website']}' target='_blank'>{$ibforums->skin['P_WEBSITE']}</a> ";
  699.         }
  700.         
  701.         if ($member['icq_number'])
  702.         {
  703.             $member['icq_icon'] = "<a href=\"javascript:PopUp('{$this->base_url}&act=ICQ&MID={$member['id']}','Pager','450','330','0','1','1','1')\">{$ibforums->skin[P_ICQ]}</a> ";
  704.         }
  705.         
  706.         if ($member['aim_name'])
  707.         {
  708.             $member['aol_icon'] = "<a href=\"javascript:PopUp('{$this->base_url}&act=AOL&MID={$member['id']}','Pager','450','330','0','1','1','1')\">{$ibforums->skin[P_AOL]}</a> ";
  709.         }
  710.         
  711.         //-----------------------------------------------------
  712.         
  713.         return $member;
  714.     
  715.     }
  716.     
  717.     /*********************************************************************/
  718.     // Render the delete button
  719.     /*********************************************************************/
  720.     
  721.     function delete_button($post_id, $poster) {
  722.         global $ibforums;
  723.         
  724.         if ($ibforums->member['id'] == "" or $ibforums->member['id'] == 0) {
  725.             return "";
  726.         }
  727.         
  728.         $button = "<a href=\"javascript:delete_post('{$this->base_url}&act=Mod&CODE=04&f={$this->forum['id']}&t={$this->topic['tid']}&p={$post_id}&st={$ibforums->input[st]}')\">{$ibforums->skin[P_DELETE]}</a>";
  729.         
  730.         if ($ibforums->member['g_is_supmod']) return $button;
  731.         if ($this->moderator['delete_post']) return $button;
  732.         if ($poster['id'] == $ibforums->member['id'] and ($ibforums->member['g_delete_own_posts'])) return $button;
  733.         return "";
  734.     }
  735.     
  736.     /*********************************************************************/
  737.     // Render the edit button
  738.     /*********************************************************************/
  739.     
  740.     function edit_button($post_id, $poster) {
  741.         global $ibforums;
  742.         
  743.         if ($ibforums->member['id'] == "" or $ibforums->member['id'] == 0) {
  744.             return "";
  745.         }
  746.         
  747.         $button = "<a href=\"{$this->base_url}&act=Post&CODE=08&f={$this->forum['id']}&t={$this->topic['tid']}&p={$post_id}&st={$ibforums->input[st]}\">{$ibforums->skin[P_EDIT]}</a>";
  748.         
  749.         if ($ibforums->member['g_is_supmod']) return $button;
  750.         if ($this->moderator['edit_post']) return $button;
  751.         if ($poster['id'] == $ibforums->member['id'] and ($ibforums->member['g_edit_posts'])) return $button;
  752.         return "";
  753.     }
  754.     
  755.     
  756.     /*********************************************************************/
  757.     // Render the IP address
  758.     /*********************************************************************/
  759.     
  760.     function view_ip($row, $poster) {
  761.         global $ibforums;
  762.         
  763.         if ($ibforums->member['g_is_supmod'] != 1 && $this->moderator['view_ip'] != 1) {
  764.             return "";
  765.         } else {
  766.             $row['ip_address'] = $poster['mgroup'] == $ibforums->vars[SUPAD_GROUP]
  767.                           ? "[ ---------- ]"
  768.                           : "[ <a href='http://www.nic.com/cgi-bin/whois.cgi?query={$row['ip_address']}' target='_blank'>{$row['ip_address']}</a> ]";
  769.             return $this->html->ip_show($row['ip_address']);
  770.         }
  771.     
  772.     }
  773.     
  774.     
  775.     /*********************************************************************/
  776.     // Render the moderator links
  777.     /*********************************************************************/
  778.     
  779.     function moderation_panel() {
  780.         global $ibforums;
  781.         
  782.         $mod_links = "";
  783.         
  784.         if (!isset($ibforums->member['id'])) return "";
  785.         
  786.         $skcusgej = 0;
  787.         
  788.         if ($ibforums->member['id'] == $this->topic['starter_id'])
  789.         {
  790.             $skcusgej = 1;
  791.         }
  792.         
  793.         if ($ibforums->member['g_is_supmod'] == 1)
  794.         {
  795.             $skcusgej = 1;
  796.         }
  797.         
  798.         if ($this->moderator['mid'] != "")
  799.         {
  800.             $skcusgej = 1;
  801.         }
  802.         
  803.         if ($skcusgej == 0)
  804.         {
  805.                    return "";
  806.         }
  807.         
  808.         $actions = array( 'MOVE_TOPIC', 'CLOSE_TOPIC', 'OPEN_TOPIC', 'DELETE_TOPIC', 'EDIT_TOPIC', 'PIN_TOPIC', 'UNPIN_TOPIC' );
  809.         
  810.         foreach( $actions as $key )
  811.         {
  812.             if ($ibforums->member['g_is_supmod'])
  813.             {
  814.                 $mod_links .= $this->append_link($key);
  815.             }
  816.             elseif ($this->moderator['mid'])
  817.             {
  818.                 if ($key == 'RECOUNT')
  819.                 {
  820.                     $mod_links .= $this->append_link($key);
  821.                 }
  822.                 else
  823.                 {
  824.                     if ($this->moderator[ strtolower($key) ])
  825.                     {
  826.                         $mod_links .= $this->append_link($key);
  827.                     }
  828.                 }
  829.             }
  830.             elseif ($key == 'OPEN_TOPIC' or $key == 'CLOSE_TOPIC')
  831.             {
  832.                 if ($ibforums->member['g_open_close_topics'])
  833.                 {
  834.                     $mod_links .= $this->append_link($key);
  835.                 }
  836.             }
  837.             elseif ($key == 'EDIT_TOPIC')
  838.             {
  839.                 if ($ibforums->member['g_edit_own_topics'])
  840.                 {
  841.                     $mod_links .= $this->append_link($key);
  842.                 }
  843.             }
  844.             elseif ($key == 'DELETE_TOPIC')
  845.             {
  846.                 if ($ibforums->member['g_delete_own_topics'])
  847.                 {
  848.                     $mod_links .= $this->append_link($key);
  849.                 }
  850.             }
  851.         }
  852.         
  853.         // Do we have a mod CP link to show?
  854.         
  855.         if ($ibforums->member['g_is_supmod'] or $this->moderator['mid'])
  856.         {
  857.             $mod_cp = $this->html->mod_cp_link( $this->forum['id'] );
  858.         }
  859.         
  860.         if ($mod_links != "")
  861.         {
  862.             return $this->html->Mod_Panel($mod_links, $this->forum['id'], $this->topic['tid'], $mod_cp);
  863.             
  864.         }
  865.     
  866.     }
  867.     
  868.     function append_link( $key="" ) {
  869.         global $ibforums;
  870.         
  871.         if ($key == "") return "";
  872.         
  873.         if ($this->topic['state'] == 'open'   and $key == 'OPEN_TOPIC') return "";
  874.         if ($this->topic['state'] == 'closed' and $key == 'CLOSE_TOPIC') return "";
  875.         if ($this->topic['state'] == 'moved'  and ($key == 'CLOSE_TOPIC' or $key == 'MOVE_TOPIC')) return "";
  876.         if ($this->topic['pinned'] == 1 and $key == 'PIN_TOPIC')   return "";
  877.         if ($this->topic['pinned'] == 0 and $key == 'UNPIN_TOPIC') return "";
  878.         
  879.         ++$this->colspan;
  880.         
  881.         return $this->html->mod_wrapper($this->mod_action[$key], $ibforums->lang[ $key ]);
  882.     }
  883.     
  884.     /*********************************************************************/
  885.     // Render the reply button
  886.     /*********************************************************************/
  887.  
  888.     function reply_button() {
  889.         global $ibforums;
  890.         
  891.         if ($this->topic['state'] == 'closed') {
  892.             return $ibforums->skin[A_LOCKED_B];
  893.         }
  894.         
  895.         if ($this->topic['state'] == 'moved') {
  896.             return $ibforums->skin[A_MOVED_B];
  897.         }
  898.         
  899.         if ($this->topic['poll_state'] == 'closed') {
  900.             return $ibforums->skin[A_POLLONLY_B];
  901.         }
  902.         
  903.         return "<a href='{$this->base_url}&act=Post&CODE=02&f=".$this->forum['id']."&t=".$this->topic['tid']."'>".$ibforums->skin[A_REPLY]."</a>";
  904.     
  905.     }
  906.     
  907.     function check_access() {
  908.         global $ibforums, $std, $HTTP_COOKIE_VARS;
  909.         
  910.         $return = 1;
  911.         
  912.         $this->m_group = $ibforums->member['mgroup'];
  913.         
  914.         if ($this->forum['read_perms'] == '*')
  915.         {
  916.             $return = 0;
  917.         }
  918.         else if (preg_match( "/(^|,)$this->m_group(,|$)/", $this->forum['read_perms'] ) )
  919.         {
  920.             $return = 0;
  921.         }
  922.         
  923.         if ($this->forum['password'] != "")
  924.         {
  925.         
  926.             if ( ! $c_pass = $std->my_getcookie('iBForum'.$this->forum['id']) )
  927.             {
  928.                 return 1;
  929.             }
  930.         
  931.             if ( $c_pass == $this->forum['password'] )
  932.             {
  933.                 return 0;
  934.             }
  935.             else
  936.             {
  937.                 return 1;
  938.             }
  939.         }
  940.         
  941.         return $return;
  942.     
  943.     }
  944.     
  945.     /*********************************************************************/
  946.     // Process and parse the poll
  947.     /*********************************************************************/   
  948.     
  949.     function parse_poll() {
  950.         global $ibforums, $DB, $std;
  951.         
  952.         $html        = "";
  953.         $check       = 0;
  954.         $poll_footer = "";
  955.         
  956.         $ibforums->lang      = $std->load_words($ibforums->lang, 'lang_post', $ibforums->lang_id);
  957.         
  958.         require "./Skin/".$ibforums->skin_id."/skin_poll.php";
  959.         
  960.         $this->poll_html = new skin_poll();
  961.         
  962.         // Get the poll information...
  963.         
  964.         $DB->query("SELECT * FROM ibf_polls WHERE tid='".$this->topic['tid']."'");
  965.         $poll_data = $DB->fetch_row();
  966.         
  967.         if (! $poll_data['pid']) {
  968.             return;
  969.         }
  970.         
  971.         //----------------------------------
  972.         
  973.         $delete_link = "";
  974.         $edit_link   = "";
  975.         $can_edit    = 0;
  976.         $can_delete  = 0;
  977.         
  978.         if ($this->moderator['edit_post'])
  979.         {
  980.             $can_edit = 1;
  981.         }
  982.         if ($this->moderator['delete_post'])
  983.         {
  984.             $can_delete = 1;
  985.         }
  986.         
  987.         if ($ibforums->member['g_is_supmod'] == 1)
  988.         {
  989.             $can_edit   = 1;
  990.             $can_delete = 1;
  991.         }
  992.         
  993.         if ($can_edit == 1)
  994.         {
  995.             $edit_link   = $this->poll_html->edit_link($this->topic['tid'], $this->forum['id'] );
  996.         }
  997.         
  998.         if ($can_delete == 1)
  999.         {
  1000.             $delete_link = $this->poll_html->delete_link($this->topic['tid'], $this->forum['id'] );
  1001.         }
  1002.         
  1003.         //----------------------------------
  1004.         
  1005.         $html = $this->poll_html->ShowPoll_header($this->topic['tid'], $edit_link, $delete_link);
  1006.         
  1007.         //----------------------------------
  1008.         
  1009.         $voter = array( 'id' => 0 );
  1010.         
  1011.         // Have we voted in this poll?
  1012.         
  1013.         $DB->query("SELECT member_id from ibf_voters WHERE member_id='".$ibforums->member['id']."' and tid='".$this->topic['tid']."'");
  1014.         $voter = $DB->fetch_row();
  1015.         
  1016.         if ($voter['member_id'] != 0)
  1017.         {
  1018.             $check = 1;
  1019.             $poll_footer = $ibforums->lang['poll_you_voted'];
  1020.         }
  1021.         
  1022.         if ( ($poll_data['starter_id'] == $ibforums->member['id']) and ($ibforums->vars['allow_creator_vote'] != 1) )
  1023.         {
  1024.             $check = 1;
  1025.             $poll_footer = $ibforums->lang['poll_you_created'];
  1026.         }
  1027.             
  1028.         if (! $ibforums->member['id'] ) {
  1029.             $check = 1;
  1030.             $poll_footer = $ibforums->lang['poll_no_guests'];
  1031.         }
  1032.         
  1033.         if ($check == 1)
  1034.         {
  1035.             // Show the results
  1036.             $poll_answers = unserialize(stripslashes($poll_data['choices']));
  1037.             reset($poll_answers);
  1038.             foreach ($poll_answers as $entry)
  1039.             {
  1040.                 $id     = $entry[0];
  1041.                 $choice = $entry[1];
  1042.                 $votes  = $entry[2];
  1043.                 
  1044.                 if (!$choice)
  1045.                 {
  1046.                     continue;
  1047.                 }
  1048.                 
  1049.                 $percent = $votes == 0 ? 0 : $votes / $poll_data['votes'] * 100;
  1050.                 $percent = sprintf( '%.2f' , $percent );
  1051.                 $width   = $percent > 0 ? (int) $percent * 2 : 0;
  1052.                 $html   .= $this->poll_html->Render_row_results($votes, $id, $choice, $percent, $width);
  1053.             }
  1054.         }
  1055.         else
  1056.         {
  1057.             $poll_answers = unserialize(stripslashes($poll_data['choices']));
  1058.             reset($poll_answers);
  1059.             foreach ($poll_answers as $entry)
  1060.             {
  1061.                 $id     = $entry[0];
  1062.                 $choice = $entry[1];
  1063.                 $votes  = $entry[2];
  1064.                 
  1065.                 if (!$choice)
  1066.                 {
  1067.                     continue;
  1068.                 }
  1069.                 
  1070.                 $html   .= $this->poll_html->Render_row_form($votes, $id, $choice);
  1071.             }
  1072.             $poll_footer = "<input type='submit' name='submit'   value='{$ibforums->lang['poll_add_vote']}' class='forminput'> ".
  1073.                            "<input type='submit' name='nullvote' value='{$ibforums->lang['poll_null_vote']}' class='forminput'>";
  1074.         }
  1075.         
  1076.         $html .= $this->poll_html->ShowPoll_footer($poll_footer);
  1077.         
  1078.         return $html;
  1079.     }
  1080.     
  1081.     
  1082.     function return_last_post()
  1083.     {
  1084.         global $ibforums, $DB, $std;
  1085.         
  1086.         $st = 0;
  1087.             
  1088.         if ($this->topic['posts'])
  1089.         {
  1090.             if ( (($this->topic['posts'] + 1) % $ibforums->vars['display_max_posts']) == 0 )
  1091.             {
  1092.                 $pages = ($this->topic['posts'] + 1) / $ibforums->vars['display_max_posts'];
  1093.             }
  1094.             else
  1095.             {
  1096.                 $number = ( ($this->topic['posts'] + 1) / $ibforums->vars['display_max_posts'] );
  1097.                 $pages = ceil( $number);
  1098.             }
  1099.             
  1100.             $st = ($pages - 1) * $ibforums->vars['display_max_posts'];
  1101.         }
  1102.         
  1103.         $DB->query("SELECT pid FROM ibf_posts WHERE queued <> 1 AND topic_id='".$this->topic['tid']."' ORDER BY pid DESC LIMIT 1");
  1104.         $post = $DB->fetch_row();
  1105.         
  1106.         $std->boink_it($ibforums->base_url."&act=ST&f=".$this->topic['forum_id']."&t=".$this->topic['tid']."&st=$st&"."#entry".$post['pid']);
  1107.         exit();
  1108.                 
  1109.     }
  1110. }
  1111.  
  1112. ?>